<?php

$title                  = get_input('title');
$description            = get_input('description');
if(!$description) {
	$description = $title;
}
$user_id                = get_input('userid');
if(!$user_id)
    $user_id            = get_loggedin_userid();
$shared                 = 0;
$width                  = 640;
$height                 = 960;
$orientation            = 1;
$device_model           = get_input('device_model');
$device_uid             = get_input('device_uuid');
$lat                    = get_input('lat');
$lng                    = get_input('lng');
$location_description   = '';
$md5                    = get_input('md5');
$url                    = get_input('url');
$thumbnail_url          = get_input('thumbnail_url');
if(!$thumbnail_url) {
    $thumbnail_url = $url;
}
$timestamp              = get_input('date');
if(!$timestamp) {
    $timestamp = time();
}

$drawing_id = claim_drawing($title, $description, $user_id, $shared, 
                        $width, $height, $orientation, 
                        $device_model, $device_uid, 
                        $md5, $url, $thumbnail_url, 
                        $lat, $lng, $location_description, $timestamp);

if($drawing_id) {
    $collaborator_ids   = explode(',', get_input('collaborator_ids'));
    foreach($collaborator_ids as $collaborator_id) {
        add_drawing_collaborators($collaborator_id, $drawing_id, 1);
    }
    $tags               = explode(',',get_input('tags'));
    add_drawing_tags($drawing_id, $tags);
    echo json_encode(export_result(200, "201 Created"));
} else {
    echo json_encode(export_result(400, "400 Bad Request"));
}

?>